﻿@using RooHui.Infrastructure.Entities.Enum
@using RooHui.Tool
@{
    ViewBag.Title = "ProjectDetail";
    Layout = "~/Views/Shared/_Layout.cshtml";
    RooHui.Portal.Biz.Model.ProjectDetailModel project = ViewBag.ProjectDetail;
}
@section head{
    <link rel="stylesheet" type="text/css" href="/content/plugins/fancybox/jquery.fancybox-1.3.4.css" />
    <style type="text/css">
        table.project tr td.title
        {
            width: 25%;
            text-align: right;
            font-size: 16px;
            color: #666;
        }
        table.project tr td.filed
        {
            width: 25%;
            text-align: right;
            font-size: 18px;
        }
        .wall
        {
            padding: 10px;
            border: 1px solid #e3e3e3;
            text-shadow: 0 1px 0 #fff;
            border-radius: 4px;
            -webkit-border-radius: 4px;
            -moz-border-radius: 4px;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -ms-box-sizing: border-box;
        }
        hr
        {
            margin: 10px 0;
        }
    </style>
}
<div class="container" style="padding-top: 20px;">
    <div class="bg-light wall">
        <div class="row-fluid">
            <div class="span12">
                <div class="span8">
                    <a href="javascript:;" class="blue" style="font-size: 24px;">@project.ProductName @project.ProjectTitle</a>
                    <span style="color: #777; font-size: 12px;">项目编码：@project.ProjectCode</span><br />
                    项目融资金额：<span style="color: #e86e00;">￥ @(Math.Round(project.Financing / 10000, 2))
                        万元</span> ， 还需融资额：<span style="color: #3498DB;">￥
                            @(Math.Round(project.RemainFinancing / 10000, 2))
                            万元</span>
                    <hr />
                    <table class="project" style="width: 90%;">
                        <tr>
                            <td class="title">
                                预期年化利率：
                            </td>
                            <td class="filed">
                                <span class="poptag" style="border-bottom: 1px dashed #333; color: #e86e00;">
                                    @(project.Policies.FirstOrDefault(c => !c.IsAttach).Rate)%
                                    @if (project.Policies.Any(c => c.IsAttach))
                                    {
                                        @: + 奖励
                                                                                                            }
                                </span>
                            </td>
                            <td class="title">
                                担保公司：
                            </td>
                            <td class="filed">
                                <img style="width:20px;height:20px;" alt="@project.GuaranteeCompanyName" src="@project.GuaranteeCompanyLogo">
                                @project.GuaranteeCompanyName
                            </td>
                        </tr>
                        <tr>
                            <td class="title">
                                获取收益方式：
                            </td>
                            <td class="filed">
                                <span style="border-bottom: 1px dashed #333;">@project.Policies.FirstOrDefault(c => !c.IsAttach).BalanceType.Mapping()</span>
                            </td>
                            <td class="title">
                                融资期限：
                            </td>
                            <td class="filed">
                                @(project.ProjectCycleAmount)
                                期&nbsp;&nbsp;&nbsp;(@project.Policies.FirstOrDefault(c => !c.IsAttach).Duration
                                @(project.Policies.FirstOrDefault(c => !c.IsAttach).DurationType.Mapping())/期)
                            </td>
                        </tr>
                        <tr>
                            <td class="title">
                                手续费：
                            </td>
                            <td class="filed">
                                0.00 元
                            </td>
                            <td class="title">
                                @(((int)project.ProjectStatus < (int)ProjectStatus.Repayment) ? "预计" : "")起息日：
                            </td>
                            <td class="filed">@project.BeginDate.ToString("yyyy-MM-dd")
                            </td>
                        </tr>
                        <tr>
                            <td class="title">
                                融资进度：
                            </td>
                            <td colspan="3">
                                @{
                                    var percent = (int)(((project.Financing - project.RemainFinancing) / project.Financing) * 100);
                                    var progressStyle = percent <= 50 ? "progress-info" : percent < 100 ? "progress-warning" : "progress-success";
                                }
                                <div class="progress @progressStyle progress-striped" style="margin:0;">
                                    <div class="bar" style="width: @percent%">
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="span4">
                    <div class="tag-box tag-box-v1 text-justify" style="background-color: #fff; min-height: 160px;">
                        <strong>请填写投资金额（元）：</strong>
                        <div class="span12" style="padding-top: 10px;">
                            @{if (project.ProjectStatus != ProjectStatus.Publish)
                              {
                                <input type="button" disabled="disabled" class="btn-u btn-u-info disabled margin-bottom-10"
                                    style="margin-left: 10px;" value="投标已结束" />
                              }
                              else
                              {

                                  if (project.ReleaseTime > DateTime.Now)
                                  {
                                <input type="button" disabled="disabled" class="btn-u btn-u-info margin-bottom-10"
                                    style="margin-left: 10px;" value="立即投资" /> <span class="label label-warning">将于：@project.ReleaseTime.ToString("MM.dd HH:mm")
                                        发布</span>
                                  }
                                  else
                                  {
                                <a href="/project/projectinvestment?id=@project.ProjectId">
                                    <input type="button" class="btn-u btn-u-info margin-bottom-10" style="margin-left: 10px;"
                                        value="立即投资" />
                                </a>
                                  }
                                <ul>
                                    <li>投资单份金额：￥@project.IncreaseMoney.ToString("F2").Trim()</li>
                                    <li>个人最大投资金额：￥@project.MaxInvestment.ToString("F2")</li>
                                </ul>
                              }}
                        </div>
                        <div class="span12">
                            <hr style="margin: 10px 0;" />
                            <div>
                                如您进行投资，即表示您阅读并同意 <a href="javascript:;" class="color-green">投资协议</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="span12">
                @if (project.Policies.Any(c => c.IsAttach))
                {
                    <div class="span4">
                        <ul>
                            <li><strong style="color: Red; font-size: 20px;">奖励：</strong></li>
                            @{
                    var policies = project.Policies.Where(c => c.IsAttach).ToList();
                    foreach (var policy in policies)
                    {
                                <li><strong style="color: Red;">额外追加 @policy.Rate @(policy.SettlementType == SettlementType.Proportion ? "% 年化收益率" : "固定收益")
                                    (@policy.CycleAmount 期 @policy.Duration @policy.DurationType.Mapping()/期)</strong></li>
                    }
                            }
                        </ul>
                    </div>
                }
                @{
                    List<RooHui.Infrastructure.Entities.Entity.PromotionPolicy> list = ViewBag.PromotionPolicies;
                    if (list != null && list.Any())
                    {
                    <div class="span8">
                        <ul>
                            <li><strong style="color: Green; font-size: 20px;">促销：</strong></li>
                            @foreach (var item in list)
                            {
                                <li><strong style="color: Green;">@item.Summary</strong></li>
                            }
                        </ul>
                    </div>
                    }
                }
            </div>
        </div>
    </div>
    <div class="row-fluid">
        <div class="span8">
            <div class="wall">
                <h3>
                    项目信息</h3>
                <hr />
                <table>
                    <tr style="height: 40px;">
                        <td style="width: 25%; text-align: center;">
                            融资方代码：
                        </td>
                        <td style="width: 20%;">
                            @project.EnterpriseCode
                        </td>
                        <td style="width: 25%; text-align: center;">
                            企业授信等级：
                        </td>
                        <td style="text-align: left;">
                            @project.EnterpriseCredit
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <p style="text-indent: 24px; line-height: 20px;">
                                @project.ProjectDescription</p>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="wall" style="margin-top: 10px; min-height: 220px;">
                <h3>
                    担保信息</h3>
                <hr />
                <div class="span12">
                    <div class="span2">
                        担保公司：</div>
                    <div class="span10">@project.GuaranteeCompanyName 担保 <span class="orange" style="margin-left: 30px;">
                        100% 本息担保</span></div>
                </div>
                <div class="span12">
                    <div class="span2">
                        公司资料：</div>
                    <div class="span10" style="padding-right: 20px;">@project.GuaranteeCompanySummary</div>
                </div>
            </div>
            <div class="wall" style="margin-top: 10px; min-height: 220px;">
                <h3>
                    预期收益</h3>
                <hr />
                <p>
                    以投资@(project.Financing)为例，@(((int)project.ProjectStatus < (int)ProjectStatus.Repayment) ? "(预计)" : "")起息日为：@project.BeginDate.ToString("yyyy-MM-dd")</p>
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th width="30%">
                                预期还款时间
                            </th>
                            <th>
                                类型
                            </th>
                            <th width="30%">
                                还款金额(元)
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            var plan = project.RepaymentPlan.GroupBy(c => c.PayBackDate).OrderBy(c => c.Key).ToList();
                            for (int i = 0, len = plan.Count; i < len; i++)
                            {
                                for (int j = 0, jlen = plan[i].Count(); j < jlen; j++)
                                {
                                    var cycle = plan[i].ToList();
                            <tr>
                                @if (j == 0)
                                {
                                    <td rowspan="@plan[i].Count()">@cycle[j].PayBackDate.ToString("yyyy-MM-dd")
                                    </td>
                                }
                                <td>@cycle[j].Name
                                </td>
                                <td>
                                    ￥ @cycle[j].Value（元）
                                </td>
                            </tr> 
                                }
                            }
                        }
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                            <td colspan="2" style="color: #e86e00; font-size: 20px; text-align: right;">
                                <strong>合计收益： ￥ @plan.Sum(c => c.Sum(i => i.Value)) 元</strong>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="span4 wall" style="*width: 21%; background-color: #fcfcfc;">
            <div class="blog-twitter">
                <div class="headline headline-md">
                    <h2>
                        相关资料</h2>
                    <div style="margin-top: 10px; font-size: 16px; line-height: 30px; color: #777;">
                        合同协议</div>
                    <ul class="list-unstyled blog-photos" style="margin: 10px 0;">
                        @{
                            var agreement = project.Resource.Where(c => c.ResouceSubType == ResourceSubType.ProjectAgreement).Take(6).ToList();
                            foreach (var item in agreement)
                            {
                                if (item.PrivateLevel == PrivateLevel.Public ||
                                    (item.PrivateLevel == PrivateLevel.MemberOnly && HttpContext.Current.User.Identity.IsAuthenticated))
                                {
                            <li><a class="contract" href="@item.Path" title="@item.Name">
                                <img class="hover-effect" alt="@item.Name" src="@item.Path"></a></li>
                                }
                            }
                        }
                    </ul>
                    @{
                        var description = project.Resource.Where(c => c.ResouceSubType == ResourceSubType.ProjectDesction).Take(6).ToList();
                        if (description != null && description.Any())
                        {
                        <div style="margin-top: 10px; font-size: 16px; line-height: 30px; color: #777;">
                            其他资料</div>            
                        <ul class="list-unstyled blog-photos" style="margin: 10px 0;">
                            @{
                            foreach (var item in description)
                            {
                                if (item.PrivateLevel == PrivateLevel.Public ||
                                    (item.PrivateLevel == PrivateLevel.MemberOnly && HttpContext.Current.User.Identity.IsAuthenticated))
                                {
                                <li><a class="contract" href="@item.Path" title="@item.Name">
                                    <img class="hover-effect" alt="@item.Name" src="@item.Path"></a></li>
                                }
                            }
                            }
                        </ul>
                        }
                    }
                </div>
                <div class="headline headline-md">
                    <h2>
                        投资记录</h2>
                </div>
                <table class="table" style="width: 100%;">
                    @{
                        foreach (var item in project.Invest)
                        {
                        <tr>
                            <td>
                                <i class="icon-user grey"></i><a href="javascript:;">@item.Invester.Anonymous()</a>
                            </td>
                            <td>
                                ￥ @((item.InvestMentAmount / 10000).ToString("F2"))
                                万元
                            </td>
                            <td align="right">
                                @{int m = (int)DateTime.Now.Subtract(item.RecordDate).TotalMinutes;}
                                @if (m <= 30)
                                {
                                    @m @:分钟前
                                }
                                else
                                { 
                                    @item.RecordDate.ToString("yy-MM-dd")    
                                }
                            </td>
                        </tr>
                        }
                    }
                </table>
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript" src="/content/plugins/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.contract').fancybox();
            $('#labproject').addClass('active');
            $('.poptag').each(function () {
                $(this).popover();
            });
        });
    </script>
}
